/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package util;

import core.Doctor;
import core.ErrorLogger;
import core.SqlConnection;
import core.User;
import core.Visit;
import core.WynikiBadanProstych;
import gui.PatientForm;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import util.JCalendar.CellType;

/**
 *
 * @author Marcin
 */
public class PopUpMenu_Szczepionki extends JPopupMenu{
    JMenuItem itDodaj;
    JMenuItem itUsun;
    User me;

    PopUpMenu_Szczepionki(final JCalendar cal, final User me, final int id_szczepionki) {
        itDodaj = new JMenuItem("Zarejestruj sie");
        itUsun = new JMenuItem("Wyrejestruj sie");
    
        this.me = me;
        {
            itUsun.setEnabled(false);
        }
        if(cal.getCalendar().getSelectedRowCount() != 1 || cal.getCalendar().getSelectedColumnCount() != 1 || cal.calendarMap[cal.getCalendar().getSelectedRow()][cal.getCalendar().getSelectedColumn()] != CellType.VISIT){
            itDodaj.setEnabled(true);
            itUsun.setEnabled(false);
        }
        if(cal.getCalendar().getSelectedRowCount() != 1 || cal.getCalendar().getSelectedColumnCount() != 1 || cal.calendarMap[cal.getCalendar().getSelectedRow()][cal.getCalendar().getSelectedColumn()] == CellType.VISIT){
            itDodaj.setEnabled(false);
            itUsun.setEnabled(true);
        }
        itDodaj.addMouseListener(new MouseAdapter(){
            @Override
            public void mouseReleased(MouseEvent e) {
                cal.addEvent(JCalendar.CellType.VISIT);
                int col[] = cal.getCalendar().getSelectedColumns();
                for(int c : col){
                    if(c!=0) {
                        WynikiBadanProstych.addSzczepionki(cal.getSelectedDateStart(c), cal.getSelectedDateEnd(c), me, id_szczepionki);
                    }
                }
                cal.repaint();
            }
        });
        itUsun.addMouseListener(new MouseAdapter(){
            @Override
            public void mouseReleased(MouseEvent e) {
                cal.addEvent(JCalendar.CellType.NORMAL);
                int col[] = cal.getCalendar().getSelectedColumns();
                for(int c : col) {
                    WynikiBadanProstych.delSzczepionki(cal.getSelectedDateStart(c), cal.getSelectedDateEnd(c), me);
                }
                cal.repaint();
            }
        });
        add(itDodaj);
        add(itUsun);
    }
}
